<template>
  <div>
        <!-- 添加 -->
        <Button type="primary" @click="addMessage">添加</Button>
        <Button type="error" @click="removes">删除多个</Button>
        <!-- 搜索框 -->
        <Input v-model="filter.name">
            <Button slot="append" icon="ios-search" @click = "seachData"></Button>
        </Input>
          
        <Layout>
             <!-- 树形菜单 -->
            <Sider hide-trigger :style="{background: '#fff'}">
                <Tree :data="tree" @on-select-change="onSelectChange"></Tree>
            </Sider>
             <!-- 右侧表格 -->
            <Layout :style="{padding: '0 24px 24px'}">
                 <Table border ref="selection" @on-selection-change="onSelectionChange" :columns="columns" :data="data"></Table>
                 <page :total = "total" :page-size="filter.rows" :page-size-opts="[5,10,15,20]" @on-page-size-change="onPagesizeChange" @on-change="onPage" show-sizer></page>
            </Layout>
            <!-- 添加数据表单，对话表单 -->
            <Modal
                v-model="modelAdd"
                title="Common Modal dialog box title">
                <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                    <FormItem label="Name" prop="name">
                        <Input v-model="formValidate.name" placeholder="Enter your name"></Input>
                    </FormItem>
                    <FormItem label="Desc" prop="desc">
                        <Input v-model="formValidate.desc" placeholder="Enter your desc"></Input>
                    </FormItem>
                    <FormItem label="Pirce" prop="pirce">
                        <Input v-model="formValidate.price" placeholder="Enter your price"></Input>
                    </FormItem>
                </Form>
                <!-- 关闭弹窗，提交或取消提交数据 -->
                <div slot="footer">
                        <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                        <Button type="ghost" @click="handleReset('formValidate')">重置</Button>
                </div>
            </Modal>
        </Layout>
  </div>
      
</template>
<script>
    import {dataMixins}  from '../common/dataMixins';
    export default {
        mixins : [dataMixins],
        data () {
            return {
                type:1,
              modules:'products',
              formValidate: {
                    name: '',
                    desc:'',
                    price:''
                },
                ruleValidate: {
                    name: [
                        { required: true, message: 'The title cannot be empty', trigger: 'blur' }
                    ],
                    desc: [
                        { required: true, message: 'The desc cannot be empty', trigger: 'blur' }
                    ],
                    price: [
                        { required: true, message: 'The desc cannot be empty', trigger: 'blur' }
                    ]
                },
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '商家',
                        key: 'name',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    {
                      title:'内容',
                      key:'desc'
                    },
                    {
                      title:'价格',
                      key:'price'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.editIdata(params.row._id)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            
                                            this.remove(params.row._id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    },
                    {
                      title:'评论数',
                      key:'num'
                    },
                    {
                        title: '评论',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                           this.$router.push({path:'/comment',params:{ productsId:params.row._id },query:{productsId:params.row._id}});
                                        }
                                    }
                                }, '查看'),
                            ]);
                        }
                    }
                ]
            }
        }
    }
</script>
